package o;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import okhttp3.RealCall;
import okhttp3.RealCall.d;

public final class fun extends ful {
    static final /* synthetic */ boolean ʼ = (!fun.class.desiredAssertionStatus());
    private int ʽ = 5;
    private int ˊॱ = 32;
    private int ˋॱ = 2;
    private final List<e> ॱˊ = new ArrayList();
    private int ॱॱ = 2;

    final class e {
        static final /* synthetic */ boolean ʼ = (!fun.class.desiredAssertionStatus());
        final /* synthetic */ fun ʽ;
        public String ˊ;
        public int ˋ;
        public int ˎ;
        public int ˏ;
        public String ॱ;
        public int ᐝ = 1;

        public e(fun o_fun, String str, int i, String str2) {
            this.ʽ = o_fun;
            this.ˊ = str;
            this.ˏ = i;
            this.ॱ = str2;
            ˋ(str, i, str2);
        }

        private void ˋ(String str, int i, String str2) {
            if (ʼ || Thread.holdsLock(this.ʽ)) {
                fur ˏ;
                int i2 = 0;
                for (d ˎ : this.ʽ.ˊ) {
                    int i3;
                    ˏ = ˎ.ˎ().ˏ();
                    if (ˏ.ʻ().equals(str) && ˏ.ॱॱ() == i && ˏ.ˋ().equals(str2)) {
                        i3 = i2 + 1;
                    } else {
                        i3 = i2;
                    }
                    i2 = i3;
                }
                this.ˎ = i2;
                for (d ˎ2 : this.ʽ.ॱ) {
                    ˏ = ˎ2.ˎ().ˏ();
                    if (ˏ.ʻ().equals(str) && ˏ.ॱॱ() == i && ˏ.ˋ().equals(str2)) {
                        i2++;
                    }
                }
                this.ˋ = i2;
                return;
            }
            throw new AssertionError();
        }
    }

    public void ॱ(int i) {
        if (i < 1) {
            throw new IllegalArgumentException("max < 1: " + i);
        }
        synchronized (this) {
            this.ʽ = i;
        }
        ˏ();
    }

    public void ˊ(int i) {
        if (i < 1) {
            throw new IllegalArgumentException("max < 1: " + i);
        }
        synchronized (this) {
            this.ˊॱ = i;
        }
        ˏ();
    }

    public int ˊ() {
        return this.ॱॱ;
    }

    void ˎ(String str, int i, String str2) {
        synchronized (this) {
            if (ॱ(str, i, str2) != null) {
                return;
            }
            this.ॱˊ.add(new e(this, str, i, str2));
            ˏ();
        }
    }

    void ˊ(String str, int i, String str2) {
        synchronized (this) {
            Iterator it = this.ॱˊ.iterator();
            while (it.hasNext()) {
                e eVar = (e) it.next();
                if (eVar.ˊ.equals(str) && eVar.ˏ == i && eVar.ॱ.equals(str2)) {
                    it.remove();
                    return;
                }
            }
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    void ॱ(okhttp3.RealCall.d r3) {
        /*
        r2 = this;
        r0 = 0;
        monitor-enter(r2);
        if (r3 != 0) goto L_0x0006;
    L_0x0004:
        monitor-exit(r2);	 Catch:{ all -> 0x0022 }
    L_0x0005:
        return;
    L_0x0006:
        r1 = r3.ˎ();	 Catch:{ all -> 0x0022 }
        r1 = r2.ॱ(r1);	 Catch:{ all -> 0x0022 }
        if (r1 == 0) goto L_0x001e;
    L_0x0010:
        r0 = r2.ˏ(r3, r1);	 Catch:{ all -> 0x0022 }
    L_0x0014:
        monitor-exit(r2);	 Catch:{ all -> 0x0022 }
        r2.ˏ();
        if (r0 == 0) goto L_0x0005;
    L_0x001a:
        r2.ˋ(r3, r1);
        goto L_0x0005;
    L_0x001e:
        r2.ˊ(r3);	 Catch:{ all -> 0x0022 }
        goto L_0x0014;
    L_0x0022:
        r0 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x0022 }
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.fun.ॱ(okhttp3.RealCall$d):void");
    }

    private boolean ˏ(d dVar, e eVar) {
        if (eVar.ˋ == 0) {
            fur ˏ = dVar.ˎ().ˏ();
            if (!dVar.ˏ().ˏ(ˏ.ʻ(), ˏ.ॱॱ(), ˏ.ˋ())) {
                ˊ(ˏ.ʻ(), ˏ.ॱॱ(), ˏ.ˋ());
                ˊ(dVar);
                return false;
            }
        }
        eVar.ˋ++;
        this.ॱ.add(dVar);
        return true;
    }

    private void ˊ(d dVar) {
        this.ॱ.add(dVar);
    }

    private boolean ˏ() {
        if (ʼ || !Thread.holdsLock(this)) {
            d dVar;
            boolean z;
            List<d> arrayList = new ArrayList();
            synchronized (this) {
                Iterator it = this.ॱ.iterator();
                while (it.hasNext()) {
                    dVar = (d) it.next();
                    if (this.ˊ.size() >= this.ˋ) {
                        break;
                    }
                    int i;
                    int ˏ;
                    e ॱ = ॱ(dVar.ˎ());
                    if (ॱ != null) {
                        i = this.ˊॱ;
                        ˏ = ˏ(dVar);
                    } else {
                        i = this.ʽ;
                        ˏ = ʽ(dVar);
                    }
                    if (ˏ < i) {
                        it.remove();
                        arrayList.add(dVar);
                        this.ˊ.add(dVar);
                        if (ॱ != null) {
                            ॱ.ˎ++;
                        }
                    }
                }
                z = ॱ() > 0;
            }
            for (d dVar2 : arrayList) {
                dVar2.ॱ(ˋ());
            }
            return z;
        }
        throw new AssertionError();
    }

    void ˎ(d dVar) {
        synchronized (this) {
            e ॱ = ॱ(dVar.ˎ());
            if (ॱ != null) {
                ॱ.ˋ--;
                ॱ.ˎ--;
                if (dVar.ˋ()) {
                    fur ˏ = dVar.ˎ().ˏ();
                    ॱ.ᐝ = dVar.ˏ().ˎ(ˏ.ʻ(), ˏ.ॱॱ(), ˏ.ˋ());
                }
            }
        }
        ॱ(this.ˊ, dVar);
    }

    void ˎ(RealCall realCall) {
        ॱ(this.ʻ, realCall);
    }

    private <T> void ॱ(Deque<T> deque, T t) {
        synchronized (this) {
            if (deque.remove(t)) {
                Runnable runnable = this.ˏ;
            } else {
                throw new AssertionError("Call wasn't in-flight!");
            }
        }
        if (!ˏ() && runnable != null) {
            runnable.run();
        }
    }

    private int ˏ(d dVar) {
        int i = 0;
        for (e eVar : this.ॱˊ) {
            int i2;
            if (eVar.ˊ.equals(dVar.ˊ())) {
                i2 = eVar.ˎ + i;
            } else {
                i2 = i;
            }
            i = i2;
        }
        return i;
    }

    private int ʽ(d dVar) {
        return ˋ(dVar) - ˏ(dVar);
    }

    private e ॱ(fus o_fus) {
        return ॱ(o_fus.ˏ().ʻ(), o_fus.ˏ().ॱॱ(), o_fus.ˏ().ˋ());
    }

    private e ॱ(String str, int i, String str2) {
        for (e eVar : this.ॱˊ) {
            if (eVar.ˊ.equals(str) && eVar.ˏ == i && eVar.ॱ.equals(str2)) {
                return eVar;
            }
        }
        return null;
    }

    private void ˋ(d dVar, e eVar) {
        Object obj = null;
        synchronized (this) {
            if (eVar.ˋ == this.ˊॱ + 1) {
                fur ˏ = dVar.ˎ().ˏ();
                eVar.ᐝ = dVar.ˏ().ˎ(ˏ.ʻ(), ˏ.ॱॱ(), ˏ.ˋ());
            }
            int i = eVar.ᐝ;
            if ((this.ˊॱ * i) * this.ˋॱ < eVar.ˋ && i < this.ॱॱ) {
                obj = 1;
                eVar.ᐝ++;
                eVar.ˎ++;
            }
        }
        if (obj != null) {
            ftz ˎ = dVar.ˏ().ˎ(dVar.ˎ().ʽ().ॱ("Http2ConnectionIndex", Integer.toString(i + 1)).ॱ());
            if (ˎ instanceof RealCall) {
                RealCall realCall = (RealCall) ˎ;
                fua anonymousClass4 = new fua(this) {
                    final /* synthetic */ fun ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void onFailure(ftz o_ftz, IOException iOException) {
                    }

                    public void onResponse(ftz o_ftz, fvb o_fvb) throws IOException {
                        if (o_fvb != null) {
                            o_fvb.close();
                        }
                    }
                };
                Objects.requireNonNull(realCall);
                d dVar2 = new d(realCall, anonymousClass4);
                dVar2.ʼ();
                synchronized (this) {
                    this.ˊ.add(dVar2);
                }
                dVar2.ॱ(ˋ());
            }
        }
    }
}
